package com.abso.sunlight.explorer.events;

import java.util.EventObject;

/**
 * An event describing a change in the set of saved searches.
 */
public class SearchStateChangedEvent extends EventObject {

    /** Serial version identifier. */
    private static final long serialVersionUID = -3827945324364892225L;

    /**
     * Event's type.
     */
    public enum Type {
        LEGISLATOR_SEARCH_ADDED, LEGISLATOR_SEARCH_DELETED, LEGISLATOR_SEARCH_QUERY_CHANGED, LEGISLATOR_SEARCH_RENAMED, LEGISLATOR_SEARCH_PERFORMED;
    }

    /** The starting search (could be null) from which the current event's source originated. */
    private Object fromSearch;

    /** Event's type. */
    private Type type;

    /**
     * Constructs a new event.
     * 
     * @param type
     *            the event's type.
     * @param search
     *            the event's source.
     */
    public SearchStateChangedEvent(Type type, Object search) {
        this(type, search, null);
    }

    /**
     * Constructs a new event.
     * 
     * @param type
     *            the event's type.
     * @param search
     *            the event's source.
     * @param fromSearch
     *            The starting search (could be null) from which <i>search</i> originated.
     */
    public SearchStateChangedEvent(Type type, Object search, Object fromSearch) {
        super(search);
        this.type = type;
        this.fromSearch = fromSearch;
    }

    /**
     * Returns the event's type.
     * 
     * @return   the event's type.
     */
    public Type getType() {
        return type;
    }

    /**
     * Returns the starting search (could be null) from which <i>search</i> originated.
     * 
     * @return   the starting search (could be null) from which <i>search</i> originated.
     */
    public Object getFromSearch() {
        return fromSearch;
    }

}
